var React = require('react-native');

var {
  View,
  Text,
  PixelRatio,
  TextInput,
  Platform,
  TouchableOpacity,
  StyleSheet
} = React;


var androidPropties = {};
if (Platform.OS === 'android') {
  androidPropties['underlineColorAndroid'] = 'transparent';
}

var noop = () => {};

var Input = React.createClass({

  getDefaultProps() {
    return {
      onFocus: noop,
	    onBlur: noop,

    }
  },


  getInitialState(){
    return {
      isEditable: false
    }
  },


  render() {

    return (
      <View
        style={styles.view}
        onLayout={this.props.onTextLayout}>

        {/*label*/}
        <Text style={[styles.text, this.props.textStyle]}>
          {this.props.text}
        </Text>

        {/*text-input*/}
        <TextInput
          {...androidPropties}
          ref={(input) => this.input = input}
          onBlur={this.props.onBlur}
          autoCapitalize={'none'}
          autoCorrect={false}
          value={this.props.value}
          style={[styles.input, this.props.inputStyle, Platform.OS==='android' && {
              padding: 0
            }]}
          textAlign={Platform.OS === 'ios' ? 'right' : 'end'}
          keyboardType={this.props.keyboardType}
          maxLength={this.props.maxLength}
          placeholder={this.props.placeholder}
          placeholderTextColor='#bbc1c6'
          onFocus={this._handleOnFocus}
          onChangeText={this.props.onChangeText}
          autoFocus={this.props.autoFocus}
        />
      </View>
    )
  },


  /**
   * 处理聚焦时间
   */
    _handleOnFocus() {
    this.input.focus();
    this.props.onFocus();
  }
});


var styles = StyleSheet.create({
  view: {
    padding: 15,
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'center',
    borderBottomWidth:  1 / PixelRatio.get(),
    borderBottomColor: '#e1e1e1'
  },
  text: {
    fontSize: 14,
    color: '#333'
  },
  input: {
    marginRight: 5,
    width: 150,
    height: 26,
    fontSize: 14,
    color: '#939495',
    backgroundColor: '#fff',
  }
});


module.exports = Input;
